<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<script src="../vue.js"></script>
<style>
  .list-item {
    width: 25px;
    height: 25px;
    display: inline-block;
    margin-right: 10px;
    background-color: pink;
    border-radius: 50%;
    text-align: center;
    color: #fff;
  }

  .list-enter-active,
  .list-leave-active {
    transition: all 1s;
  }

  .list-enter,
  .list-leave-to {
    opacity: 0;
    transform: translateY(45deg);
  }
</style>

<body>
  <div id="app">
    <!-- <button @click="itemsUpate">随机生成一组数字</button> -->
    <button @click="add">随机插入一个数字</button>
    <button @click="remove">随机移除一个数字</button>
    <transition-group name="list" tag="p">
      <span v-for="(item,index) in items" :key="item" class="list-item">{{item}}</span>
    </transition-group>
  </div>


  <script>
    var vm = new Vue({
      el: "#app",
      data: {
        items: [1, 2, 3, 4, 5, 6, 7, 8, 9],
        nextNum: 0
      },
      methods: {
        // itemsUpate() {
        //   let arr = []
        //   for (let i = 0; i < this.randomIndex(); i++) {
        //     console.log(1);
        //     arr[i] = this.randomIndex()
        //   }
        //   this.items = arr
        // },
        add() {
          this.items.splice(this.randomIndex(), 0, this.randomIndex())
        },
        remove() {
          this.items.splice(this.randomIndex(), 1)
        },
        randomIndex() {
          return Math.floor(Math.random() * this.items.length);
        },
      }
    })
  </script>
</body>

</html>